#include "include/common.h"
#include "include/core/coroutine.h"
#include "include/core/sched.h"
#include "include/core/cpu.h"

extern void env_init();

void* coroutine_fun(void* arg) {
    coroutine_t* self;

    __asm__("":"=d"(self));

    for (int i = 0; i < 100000; ++i) {
        printf("协程 ·%s· 获得调度\n", self->name);
        sleep(1);
    }
}

int main() {
    cpu_init();
    env_init();

    // 开始调度
    sleep(1);   // 等待1s,让模拟时钟中断的线程启动完毕
    start_cpu();

    // 再创建两个协程用于调度
    coroutine_create(NULL, coroutine_fun, "c1", 2);
    coroutine_create(NULL, coroutine_fun, "c2", 1);
    coroutine_create(NULL, coroutine_fun, "c3", 1);

    getchar();

    return 0;
}